<?php
namespace Modules\Home\Services;

use Common\Models\UserModel;
use Common\Models\UserInfoModel;

class UserInfoService {
  public function create($data) {
    $data['create_time'] = time();

    $userInfoModel = new UserInfoModel($data);
    try {
      if(!$userInfoModel -> create()) {
        $messages = $userInfoModel -> getMessages();
        throw new \Exception($messages[0] -> getMessage());
      }
    } catch(\Exception $e) {
      UserModel::findFirst('user_id = ' . $data['user_id']) -> delete();
      return ['code' => -1, 'message' => $e -> getMessage()];
    }

    return ['code' => 0, 'user_info' => $userInfoModel];
  }
}
?>